"use strict";
cc._RF.push(module, 'b7ff1HrJAxFk6Ti9Epxw4mg', 'Mass');
// scripts/Game/Obj/Mass.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var data_control_1 = require("../../engines/libs/data_control");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, menu = _a.menu, disallowMultiple = _a.disallowMultiple;
var Mass = /** @class */ (function (_super) {
    __extends(Mass, _super);
    function Mass() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        // private target : cc.Node = null;
        _this.iMass = 1;
        _this.position = new cc.Vec2();
        _this.velocity = new cc.Vec2();
        _this.allForce = [];
        _this.airRatio = 0;
        _this.setTime = false;
        _this.force = null;
        _this.onTouched = null;
        return _this;
    }
    Mass.prototype.onLoad = function () {
        this.position = this.node.getPosition();
    };
    Mass.prototype.update = function (dt) {
        // if(this.setTime){
        //     this.AddForce(this.position.sub(this.target.getPosition()).normalize().scale(this.force))
        // }
        var totalForce = data_control_1.default.AllArraySum(this.allForce);
        var airFri = this.velocity.normalize().mul(-1);
        var airFriRatio = this.velocity.mag() * Math.pow(this.airRatio, 2);
        airFri.scaleSelf(cc.v2(airFriRatio, airFriRatio));
        totalForce.addSelf(airFri);
        this.velocity = this.velocity.add(totalForce.scale(cc.v2(this.iMass, this.iMass)).mul(dt));
        // this.node.angle = -data_control.GetAngle(this.velocity);
        this.position.addSelf(this.velocity.mul(dt));
        // console.warn(this.velocity.x,this.velocity.y);
        this.node.setPosition(this.position);
    };
    Mass.prototype.lateUpdate = function (dt) {
        // if(this.target.getPosition().sub(this.position).mag()<=50){
        //     this.onTouched && this.onTouched();
        //     this.node.destroy();
        // }
        this.allForce = [];
    };
    Mass.prototype.AddForce = function (force) {
        this.allForce.push(force);
    };
    Mass.prototype.SetVelocity = function (value) {
        this.velocity = value;
    };
    Mass.prototype.SetPosition = function (value) {
        this.position = value;
        this.node.setPosition(value);
    };
    Mass = __decorate([
        ccclass,
        menu('工具组件/质点')
    ], Mass);
    return Mass;
}(cc.Component));
exports.default = Mass;

cc._RF.pop();